package com.cyy.user.textbluetoothble.Adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cyy.user.textbluetoothble.R;

import java.util.List;

/**
 * Created by USER on 2016-10-31.
 */
public class DeviceAdapter extends BaseAdapter {

    private Context context ;
    private List<BluetoothDevice> mList ;
    public DeviceAdapter(Context context,List<BluetoothDevice> list){
        this.context = context;
        this.mList = list;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder;
        if(view==null){
            view = LayoutInflater.from(context).inflate(R.layout.item_device,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.tv_name = (TextView) view.findViewById(R.id.text_name);
            viewHolder.tv_address = (TextView) view.findViewById(R.id.text_address);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_name.setText(mList.get(i).getName());
        viewHolder.tv_address.setText(mList.get(i).getAddress());
        return view;
    }
    class ViewHolder{
        TextView tv_name;
        TextView tv_address;
    }
}
